﻿using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XjjXmm.Spider.biquge
{
    internal class HttpGBKHandel : DelegatingHandler
    {


        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {


            var response = await base.SendAsync(request, cancellationToken);
            var contentType = response.Content.Headers.ContentType;
            if (contentType != null && string.IsNullOrEmpty(contentType?.CharSet))
            { 
                contentType.CharSet = "gbk"; 
            }
            //result.Headers.Add("Content-Type", "text/html; charset=gbk");
            // result.Content.Headers.ContentType["Content-Type"] = "text/html; charset=gbk";
            //result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html; charset=gbk");
            return response;
        }
    }
}
